﻿@using GTAuto.DAL.DAL
@using GTAuto.DAL.Entities
@model GTAuto.DAL.Entities.GTModelModification
@{
    ViewBag.Title = "ModificationEdit";
    Layout = "~/Views/Shared/_Layout.cshtml";
    List<string> err = ViewBag.Errs;

    List<GTPropertyCategory> activeCats = ViewBag.ActivCategories;
    List<GTModelModificationProperty> modelModificationProperties = ViewBag.ModelModificationProperties;
    
}
<h4 class="alert_info">
    @if (Model.Id > 0)
    {
        <div>
            Редактирование модификации</div>
    }
    else
    {
  
        <div>
            Создание новой модификации</div>
    }
</h4>
@using (Html.BeginForm("ModificationEdit", "DiscsModifications", FormMethod.Post, new { @class = "jNice", enctype = "multipart/form-data" }))
{

    if (err != null && err.Count != 0)
    {

        foreach (var er in err)
        {

    <h4 class="alert_error">
        @er</h4>

        }
    }
    if (ViewBag.Succes != null)
    {
    <h4 class="alert_success">
        @ViewBag.Succes</h4>
    }

    @Html.Hidden("Id", Model.Id)
    
    <article class="module width_full">
        <header><h3>Данные о модификации</h3></header>
        <div class="module_content">
            <fieldset>
                <label>Название</label>
                <input type="text" id="Name" name="Name" value="@Model.Name" />
            </fieldset>
            <fieldset > <!-- to make two field float next to one another, adjust values accordingly -->
                <label>Модель:</label>
                <input type="text" disabled="disabled" value="@ViewBag.ModelName" />
            </fieldset>
            
            
             <fieldset style="width: 100%; float: left; margin-right: 3%;">
                 <label>
                    Лого(круп.) :</label><input type="file"  id="LogoPath" name="LogoPath" value="@Model.LogoPath" />
            </fieldset>

             @if (!string.IsNullOrEmpty(Model.LogoPath))
             {
                <p>
                    <img src="@string.Format("{0}/{1}", DALSettngs.Singleton.Get("BrendLogosAdminView").Value, Model.LogoPath)"/>
                </p>
             }
              <fieldset style="width: 100%; float: left; margin-right: 3%;">
                 <label>
                    Лого(мелк.) :</label><input type="file" class="text-long" id="SmallLogoPath" name="SmallLogoPath" value="@Model.SmallLogoPath" />
            </fieldset>
            
             @if (!string.IsNullOrEmpty(Model.SmallLogoPath))
             {
                <p>
                    <img src="@string.Format("{0}/{1}", DALSettngs.Singleton.Get("BrendLogosAdminView").Value, Model.SmallLogoPath)"/>
                </p>
             }
            
            

            <div class="clear"></div>
        </div>
        <footer>
            <div class="submit_link">
               
                <input type="submit" value="Сохранить" class="alt_btn">
               
            </div>
        </footer>
    </article>

    <!-- end of post new article -->
    <div class="spacer">
    </div>
    foreach (var cat in activeCats)
    {
        var props = DALModificationProperty.Singleton.GetByCategory(cat.Id);

    <article class="module width_full">
            <header><h3 class="tabs_involved">@cat.Name</h3>
            </header>
            <table class="tablesorter" cellSpacing="0">
                <tbody> 
                    @{
                       var gtModelModificationProperties = modelModificationProperties.Where(x => x.ModificationProperty.Category == cat.Id).ToList();
                    }
                     @foreach (GTModelModificationProperty item in gtModelModificationProperties)
                     {
                         string propval = "";
                         var mpv = DALModificationPropertyValue.Singleton.Get(Model.Id,item.PropertyId);
                         if (mpv != null)
                         {
                             propval = mpv.Value;
                         }


                         <tr>
                        <td style="width:400px;">@item.ModificationProperty.Name
                        </td>
                             <td >
                                 
                                  @if (item.ModificationProperty.Type == 2)
                                  {
                                     @Html.DropDownList(string.Format("prop_{0}", item.PropertyId), new SelectList(DALModificationPropertySelectValue.Singleton.GetByPropertyId(item.PropertyId), "Value", "Value", propval))
                                  }
                                 
                                 @if (item.ModificationProperty.Type == 1)
                                 {
                                    <span> <input style="width:100%;" type="text" name="@string.Format("prop_{0}", item.PropertyId)"  id="@string.Format("prop_{0}", item.PropertyId)" value="@propval"> </span>
                                 }

                             </td> 
                    </tr>
                     }
                </tbody>
            </table>
        
        </article>
    }
}
<!-- end of post new article -->
<div class="spacer">
</div>